<script type="text/javascript" charset="utf-8" src="/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="/ueditor/ueditor.all.min.js"> </script>
<script type="text/javascript" charset="utf-8" src="/ueditor/lang/zh-cn/zh-cn.js"></script>
<script>
    var ue = UE.getEditor('editor',{allowDivTransToP: false, toolbars: [
            ['fullscreen', 'source', '|', 'undo', 'redo', '|', 'bold', 'underline', 'removeformat', '|', 'forecolor', 'fontfamily', 'fontsize', '|', 'indent', '|', 'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'link', 'unlink', '|', 'insertimage', 'autotypeset'
            ]
        ]
    });
    ue.ready(function() {
        ue.execCommand('serverparam', '_token', '{{ csrf_token() }}');
    });
    layui.use(['layer', 'table', 'form','laydate'], function () {
        var form = layui.form;
        var layer = layui.layer;
        //监听提交
        form.on('submit(formSubmit)', function(data){
            data.field.content = UE.getEditor('editor').getContent();
            $.ajax({
                url:"{{route('admin.articles.update')}}",
                method:'post',
                data:data.field,
                dataType:'JSON',
                success:function(res){
                    if(res.code == '0'){
                        layer.msg(res.msg,{icon: 6,time:1000},function(){
                            parent.location.reload();
                        });
                    } else{
                        layer.msg(res.msg,{shift: 6,icon: 5,time:1000});
                    }
                },
                error:function (data) {
                }
            })
            return false;
        });
        //网站
        form.on('select(website_id)', function(data) {
            $("#websites_topic_id").html('');
            var id = data.value;
            //栏目数据
            $.post("{{route('admin.websitesTopic.topicData')}}",{'website_id':id},function (d){
                var data = eval(d.data);
                _html="<option value=''>全部</option>";
                $.each(data,function (index,val){
                    _html+="<option value='"+val.id+"'>"+val.topic_name+"</option>";
                });
                console.log(_html);
                $("#websites_topic_id").html(_html);
                form.render('select');
            });
        });
    });
</script>

